<?php
namespace Admin\Controller;

use Think\Controller;

class PlatformController extends CommonController
{
    public function index()
    {
        $list = M('Seo')->select();
        $this->assign('list', $list);
        $this->display();
    }

    public function add()
    {
        if (!IS_POST) {
            $this->display();
            exit;
        }
        //执行插入
        $list = array(
            'title' => I('post.title'),
            'logo' => I('post.logo'),
            'contents' => I('post.contents'),
            'keywords' => I('post.keywords'),
            'copyright' => I('post.copyright'),
            'record' => I('post.record'),
            'code' => I('post.code')
        );
        if (M('Seo')->add($list)) {
            echo 1;
        } else {
            echo 0;
        }
    }

    /**
     * 删除
     */
    public function del()
    {
        $id = I('get.ids');
        if (M('Seo')->where('id=' . $id)->delete()) {
            $this->success('删除成功');
        } else {
            $this->error('删除失败');
        }
    }

    /**
     * 修改
     */
    public function edit()
    {
        if(!IS_POST){
            $id = I('get.id');
            //根据id查询
            $list = M('Seo')->where('id='.$id)->find();
            if(!$list){
                $this->error('数据异常');
            }else{
                $this->assign('list',$list);
                $this->display();
            }
            exit;
        }
        $where = array(
            'id'=> I('post.id')
        );
        $info = array(
            'title'=>I('post.title'),
            'logo'=>I('post.logo'),
            'keywords'=>I('post.keywords'),
            'contents'=>I('post.contents'),
            'copyright'=>I('post.copyright'),
            'record'=>I('post.record'),
            'code'=>I('post.code'),
        );
        if(false == M('Seo')->where($where)->save($info)){
            echo 0;
        }else{
            echo 1;
        }
    }
}